Ext.define('Jason.view.protal.module.systemSetting.runSql.MainViewCtrl',{
	extend : 'Wys.basic.BaseCtrl',
	alias : 'controller.runSqlViewCtrl',
	onRunSQlBtn: function(btn){
		var me = this,
			gridView = me.getView().down('#dataResult'),
			codeField = me.getView().down('#sqlInput'),
			runSqlMsg = me.getView().down('#runSqlMsg'),
			dbLink = me.getView().down('#dataSourceCombo');
		if(!dbLink.getValue()){
			EUtil.showWarning('请选择数据源');
			dbLink.focus();
			return;
		}
		if(!codeField.getValue()){
			EUtil.showWarning('请输入SQL语句');
			codeField.focus();
			return;
		}
		EUtil.RS({
			url: reqUrl.systemSetting.dataSouce.executeSQL,
			params : {
				code : dbLink.getValue(),
				sql : codeField.getValue(),
				start:0,limit:cfg.pageSize
			},
			msg : true,
			callback:function(resp){
				if(resp.success){
					if(resp.extra === null){
						runSqlMsg.setHtml(">>"+resp.msg);
						gridView.up().setActiveItem(runSqlMsg);
						return ;
					}else{
						runSqlMsg.setHtml(">>执行成功");
						gridView.up().setActiveItem(runSqlMsg);
						gridView.up().setActiveItem(gridView);
						var columns = new Array();
						Ext.Array.each(resp.extra,function(item){
							columns.push({text:item,menuDisabled:true,dataIndex:item});
						});
						gridView.reconfigure(columns);
						//Ext.create('Jason.store.module.systemSetting.RunSqlStore',{}),
						gridView.load({
							code : dbLink.getValue(),
							sql : codeField.getValue(),
						});
					}
				}else{
					runSqlMsg.setHtml('>><span style="color:red;">'+resp.msg || '执行SQL错误，请检查</span>');
				}
			}
		});
	}
})